package com.malty.mongodb.controller;

import cn.hutool.json.JSONObject;
import com.malty.mongodb.domain.entity.Employee;
import com.malty.mongodb.service.MyMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author malty
 */
@RestController
@RequestMapping("/test")
public class MongoTestController {
    @Autowired
    MyMongoService myMongoService;

    @PostMapping("/create")
    public Employee saveOne(@RequestBody Employee employee) {
        return myMongoService.saveOne(employee);
    }

    @PostMapping("/insert")
    public Employee insert(@RequestBody Employee employee) {
        return myMongoService.insert(employee);
    }

    @GetMapping("/find")
    public Employee saveOne(String id) {
        return myMongoService.findById(id);
    }

    @GetMapping("/aggregate")
    public List<Object> aggregate() {
        return myMongoService.aggregate();
    }

    @GetMapping("/exe")
    public void execute() {
        myMongoService.execute();
    }

    @DeleteMapping("/remove")
    public Boolean remove(String id) {
        return myMongoService.removeById(id);
    }
}
